package com.compass.doctor.dialog

import android.text.TextUtils
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.viewModels
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.compass.doctor.callback.OnDrugSelectClick
import com.compass.doctor.callback.OnUsefulButtonClick
import com.compass.doctor.databinding.DialogUsefulExpressionsBinding
import com.compass.doctor.ui.mine.viewmodel.UsefulExpressionsViewModel
import com.compass.doctor.ui.patient.adapter.AppendTagAdapter
import com.compass.framework.base.BaseDialog
import com.compass.framework.base.BaseDialogFragment
import com.compass.framework.decoration.NormalItemDecoration
import com.compass.framework.ext.gone
import com.compass.framework.ext.onClick
import com.compass.framework.ext.visible
import com.compass.framework.model.Tag
import com.compass.framework.toast.TipsToast
import com.compass.framework.utils.dpToPx

/**
 * Description： 常用语dialog
 * Date:2023/12/14 17:22
 */

const val USEFUL_OPT_ADD_CATE = 1 //添加分类
const val USEFUL_OPT_ADD = 2  //添加常用语
class UsefulExpressionsDialog {
    class Builder(
        activity: FragmentActivity,
        private var type: Int,
        private var onUsefulButtonClick: OnUsefulButtonClick?

    ) : BaseDialogFragment.Builder<Builder>(activity) {
        private val mBinding: DialogUsefulExpressionsBinding =
            DialogUsefulExpressionsBinding.inflate(LayoutInflater.from(activity))

        init {
            initView()
        }

        private fun initView() {
            setContentView(mBinding.root)
            setWidth(ViewGroup.LayoutParams.MATCH_PARENT)
            setHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
            setAnimStyle(BaseDialog.AnimStyle.BOTTOM)
            gravity = Gravity.BOTTOM
//            appendTagAdapter = AppendTagAdapter(2)
//            mBinding.rcyTags.apply {
//                layoutManager = LinearLayoutManager(context)
//                addItemDecoration(NormalItemDecoration().apply {
//                    setBounds(top = dpToPx(1), bottom = dpToPx(1))
//                    setFirstHeadMargin(true)
//                    setLastBottom(false)
//                })
//                adapter = appendTagAdapter
//
//            }
//            appendTagAdapter.onItemClickListener={
//                    _: View, position: Int ->
//                menuItems.remove(menuItems[position])
//                appendTagAdapter.setData(menuItems)
//            }
//            setTagsData()
            if(type == USEFUL_OPT_ADD_CATE){
                //添加常用语分组
                mBinding.refusalInfo.text = "添加分组"
                mBinding.edtInputContent.hint = "请输入分组名称"
//                mBinding.tvTagExplain.gone()
            }else{
                //添加常用语
                mBinding.refusalInfo.text = "添加常用语"
                mBinding.edtInputContent.hint = "请输入常用语"
//                mBinding.tvTagExplain.visible()
            }
            mBinding.tvCancel.onClick {
                dismiss()
            }
            mBinding.tvAdd.onClick {
                var tags = mBinding.edtInputContent.text
                if (!TextUtils.isEmpty(tags)){
                    onUsefulButtonClick?.onAddButton(tags.toString(),type)
                    dismiss()
                    return@onClick
                }
                TipsToast.showTips("请输入常用语内容")

            }
        }

    }
}